package com.niit.web.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.niit.bean.Question;
import com.niit.service.QuestionService;
import com.niit.service.impl.QuestionServiceImpl;
import com.niit.utils.WebKit;

@WebServlet("/AddQuestionController")
public class AddQuestionController extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Question q = WebKit.request2Bean(request, Question.class);
		QuestionService qs = new QuestionServiceImpl();
		if(qs.add(q)>0){
			//添加成功
			String id = qs.findMaxQuesId();
			response.sendRedirect("/qiuzhi/ShowQuestionViewController?id="+id);
		}else{
			response.sendRedirect("/qiuzhi/ShowClassify4AddQuesController");
		}
	}

}
